//
//  ViewController.m
//  BQTableViewCellDemo
//
//  Created by Zhiqiang Bao on 15-3-16.
//  Copyright (c) 2015年 Zhiqiang Bao. All rights reserved.
//

#import "ViewController.h"
#import "TestDemoCell.h"

#define kReuseKey   @"TestDemoCell"

@interface ViewController () <UITableViewDataSource, UITableViewDelegate, BQMenuTableViewCellDataSource, BQMenuTableViewCellDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *colorList;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.tableView = ({
        UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
        tableView.delegate = self;
        tableView.dataSource = self;
        [tableView registerNib:[UINib nibWithNibName:@"TestDemoCell" bundle:nil] forCellReuseIdentifier:kReuseKey];
        tableView;
    });
    
    self.colorList = @[[UIColor redColor], [UIColor purpleColor], [UIColor greenColor], [UIColor blueColor]];
    
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TestDemoCell *cell = [tableView dequeueReusableCellWithIdentifier:kReuseKey];
    
    cell.numberLabel.text = [@(indexPath.row) stringValue];
    cell.delegate = self;
    
    return cell;
}

#pragma mark - BQMenuTableViewCellDataSource、BQMenuTableViewCellDelegate

- (void)leftMenuView:(BQMenuTableViewCell *)cell didSelectAtIndex:(NSUInteger)index
{
    NSLog(@"didSelectLeft:%d", (int)index);
}

- (UIView *)leftMenuViewAtIndex:(NSUInteger)index ofCell:(BQMenuTableViewCell *)cell
{
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = _colorList[index];
    label.text = [NSString stringWithFormat:@"%d", (int)index];
    return label;
}

- (NSUInteger)leftMenuViewCountOfCell:(BQMenuTableViewCell *)cell
{
    return _colorList.count;
}

- (void)leftMenuViewHideOfCell:(BQMenuTableViewCell *)cell
{
    NSLog(@"leftMenuViewHideOfCell");
}

- (void)leftMenuViewShowCompeletelyOfCell:(BQMenuTableViewCell *)cell
{
    NSLog(@"leftMenuViewShowCompeletelyOfCell");
}

- (void)leftMenuViewShowPartlyOfCell:(BQMenuTableViewCell *)cell
{
    NSLog(@"leftMenuViewShowPartlyOfCell");
}

- (CGFloat)leftMenuViewWidthAtIndex:(NSUInteger)index ofCell:(BQMenuTableViewCell *)cell
{
    return 50 + index * 5;
}

- (void)rightMenuView:(BQMenuTableViewCell *)cell didSelectAtIndex:(NSUInteger)index
{
    NSLog(@"didSelectright:%d", (int)index);
}

- (UIView *)rightMenuViewAtIndex:(NSUInteger)index ofCell:(BQMenuTableViewCell *)cell
{
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = _colorList[index];
    label.text = [NSString stringWithFormat:@"%d", (int)index];
    return label;
}

- (NSUInteger)rightMenuViewCountOfCell:(BQMenuTableViewCell *)cell
{
    return _colorList.count;
}

- (void)rightMenuViewHideOfCell:(BQMenuTableViewCell *)cell
{
    NSLog(@"rightMenuViewHideOfCell");
}

- (void)rightMenuViewShowCompeletelyOfCell:(BQMenuTableViewCell *)cell
{
    NSLog(@"rightMenuViewShowCompeletelyOfCell");
}

- (void)rightMenuViewShowPartlyOfCell:(BQMenuTableViewCell *)cell
{
    NSLog(@"rightMenuViewShowPartlyOfCell");
}

- (CGFloat)rightMenuViewWidthAtIndex:(NSUInteger)index ofCell:(BQMenuTableViewCell *)cell
{
    return 50 + index * 5;
}

@end
